<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Enabling or disabling test unit execution</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../index.html" title="Boost.Test">
<link rel="up" href="../tests_organization.html" title="Declaring and organizing tests">
<link rel="prev" href="tests_grouping.html" title="Grouping tests into logical units by labels">
<link rel="next" href="semantic.html" title="Adding semantic to a test">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="tests_grouping.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../tests_organization.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="semantic.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_test.tests_organization.enabling"></a><a class="link" href="enabling.html" title="Enabling or disabling test unit execution">Enabling or disabling
      test unit execution</a>
</h3></div></div></div>
<p>
        The <span class="emphasis"><em>Unit Test Framework</em></span> provides a way for enabling
        or disabling a test unit execution. If a test case is disabled, it will not
        be run by the test runner. If a test suite is disabled, its status is inherited
        by the test units under its subtree, unless otherwise specified.
      </p>
<p>
        The run status can be overridden by the command line parameters: by providing
        the appropriate arguments to the command line, a disabled test may still
        be executed. The <a class="link" href="../runtime_config/test_unit_filtering.html" title="Test unit filtering">test
        unit filtering</a> section covers this feature in details.
      </p>
<div class="warning"><table border="0" summary="Warning">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../../doc/src/images/warning.png"></td>
<th align="left">Warning</th>
</tr>
<tr><td align="left" valign="top">
<p>
          There is a difference between a disabled test and a skipped test:
        </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
              a disabled test has a run status set to disabled, and is completely
              discarded by the <span class="emphasis"><em>Unit Test Framework</em></span>.
            </li>
<li class="listitem">
              a skipped test is a test that has a run status set to enabled, but
              which execution has been skipped at runtime.
            </li>
</ul></div>
</td></tr>
</table></div>
<h4>
<a name="boost_test.tests_organization.enabling.h0"></a>
        <span class="phrase"><a name="boost_test.tests_organization.enabling.unconditional_run_status"></a></span><a class="link" href="enabling.html#boost_test.tests_organization.enabling.unconditional_run_status">Unconditional
        run status</a>
      </h4>
<p>
        Decorator <a class="link" href="../utf_reference/test_org_reference/decorator_enabled.html" title="enabled / disabled (decorator)"><code class="computeroutput"><span class="identifier">disabled</span></code></a> indicates that the test
        unit's <a class="link" href="../runtime_config/test_unit_filtering.html#ref_default_run_status"><span class="emphasis"><em>default run status</em></span></a>
        is <span class="emphasis"><em>false</em></span>. This means that that test cases inside this
        test unit will not be run by default, unless otherwise specified. Decorator
        <a class="link" href="../utf_reference/test_org_reference/decorator_enabled.html" title="enabled / disabled (decorator)"><code class="computeroutput"><span class="identifier">enabled</span></code></a> indicates that the test
        unit's default run status is <span class="emphasis"><em>true</em></span>. This means that that
        test cases inside this test unit will be run by default, unless otherwise
        specified.
      </p>
<h6>
<a name="boost_test.tests_organization.enabling.h1"></a>
        <span class="phrase"><a name="boost_test.tests_organization.enabling.example_descr"></a></span><a class="link" href="enabling.html#boost_test.tests_organization.enabling.example_descr">Example: decorators
        enabled and disabled</a>
      </h6>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr><th>
                <p>
                  Code
                </p>
              </th></tr></thead>
<tbody><tr><td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_MODULE</span> <span class="identifier">decorator_05</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">test</span><span class="special">/</span><span class="identifier">included</span><span class="special">/</span><span class="identifier">unit_test</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="keyword">namespace</span> <span class="identifier">utf</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">unit_test</span><span class="special">;</span>

<span class="identifier">BOOST_AUTO_TEST_SUITE</span><span class="special">(</span><span class="identifier">suite1</span><span class="special">,</span> <span class="special">*</span> <span class="identifier">utf</span><span class="special">::</span><span class="identifier">disabled</span><span class="special">())</span>

  <span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span><span class="identifier">test1</span><span class="special">)</span>
  <span class="special">{</span>
    <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="number">1</span> <span class="special">!=</span> <span class="number">1</span><span class="special">);</span>
  <span class="special">}</span>

  <span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span><span class="identifier">test2</span><span class="special">,</span> <span class="special">*</span> <span class="identifier">utf</span><span class="special">::</span><span class="identifier">enabled</span><span class="special">())</span>
  <span class="special">{</span>
    <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="number">2</span> <span class="special">!=</span> <span class="number">2</span><span class="special">);</span>
  <span class="special">}</span>

<span class="identifier">BOOST_AUTO_TEST_SUITE_END</span><span class="special">()</span>
</pre>
              </td></tr></tbody>
</table></div>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr><th>
                <p>
                  Output
                </p>
              </th></tr></thead>
<tbody><tr><td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="special">&gt;</span> <span class="identifier">decorator_05</span>
<span class="identifier">Running</span> <span class="number">1</span> <span class="identifier">test</span> <span class="keyword">case</span><span class="special">...</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">14</span><span class="special">):</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"suite1/test2"</span><span class="special">:</span> <span class="identifier">check</span> <span class="number">2</span> <span class="special">!=</span> <span class="number">2</span> <span class="identifier">has</span> <span class="identifier">failed</span> <span class="special">[</span><span class="number">2</span> <span class="special">==</span> <span class="number">2</span><span class="special">]</span>

<span class="special">***</span> <span class="number">1</span> <span class="identifier">failure</span> <span class="identifier">is</span> <span class="identifier">detected</span> <span class="identifier">in</span> <span class="identifier">the</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"decorator_05"</span>


<span class="special">&gt;</span> <span class="identifier">decorator_05</span> <span class="special">--</span><span class="identifier">list_content</span>
<span class="identifier">suite1</span><span class="special">*</span>
    <span class="identifier">test1</span>
    <span class="identifier">test2</span><span class="special">*</span>
</pre>
              </td></tr></tbody>
</table></div>
<p>
        Syntactically, it is possible to apply both decorators <code class="computeroutput"><span class="identifier">enabled</span></code>
        and <code class="computeroutput"><span class="identifier">disabled</span></code> to the same
        test unit. This is reported as set-up error when the test program is run.
      </p>
<h4>
<a name="boost_test.tests_organization.enabling.h2"></a>
        <span class="phrase"><a name="boost_test.tests_organization.enabling.compilation_time_run_status"></a></span><a class="link" href="enabling.html#boost_test.tests_organization.enabling.compilation_time_run_status">Compilation-time
        run status</a>
      </h4>
<p>
        Decorator <a class="link" href="../utf_reference/test_org_reference/decorator_enable_if.html" title="enable_if (decorator)"><code class="computeroutput"><span class="identifier">enable_if</span></code></a> indicates that the test
        unit's <a class="link" href="../runtime_config/test_unit_filtering.html#ref_default_run_status"><span class="emphasis"><em>default run status</em></span></a>
        is either <span class="emphasis"><em>true</em></span> or <span class="emphasis"><em>false</em></span>, depending
        on the value of <code class="computeroutput"><span class="identifier">Condition</span></code>.
        This means that that test cases inside this test unit will or will not be
        run by default.
      </p>
<h6>
<a name="boost_test.tests_organization.enabling.h3"></a>
        <span class="phrase"><a name="boost_test.tests_organization.enabling.example_descr0"></a></span><a class="link" href="enabling.html#boost_test.tests_organization.enabling.example_descr0">Example:
        decorator enable_if</a>
      </h6>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr><th>
                <p>
                  Code
                </p>
              </th></tr></thead>
<tbody><tr><td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_MODULE</span> <span class="identifier">decorator_06</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">test</span><span class="special">/</span><span class="identifier">included</span><span class="special">/</span><span class="identifier">unit_test</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="keyword">namespace</span> <span class="identifier">utf</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">unit_test</span><span class="special">;</span>

<span class="keyword">const</span> <span class="keyword">bool</span> <span class="identifier">io_implemented</span> <span class="special">=</span> <span class="keyword">true</span><span class="special">;</span>
<span class="keyword">const</span> <span class="keyword">bool</span> <span class="identifier">db_implemented</span> <span class="special">=</span> <span class="keyword">false</span><span class="special">;</span>

<span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span><span class="identifier">test_io</span><span class="special">,</span>
  <span class="special">*</span> <span class="identifier">utf</span><span class="special">::</span><span class="identifier">enable_if</span><span class="special">&lt;</span><span class="identifier">io_implemented</span><span class="special">&gt;())</span>
<span class="special">{</span>
  <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="number">1</span> <span class="special">!=</span> <span class="number">1</span><span class="special">);</span>
<span class="special">}</span>

<span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span><span class="identifier">test_db</span><span class="special">,</span>
  <span class="special">*</span> <span class="identifier">utf</span><span class="special">::</span><span class="identifier">enable_if</span><span class="special">&lt;</span><span class="identifier">db_implemented</span><span class="special">&gt;())</span>
<span class="special">{</span>
  <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="number">2</span> <span class="special">!=</span> <span class="number">2</span><span class="special">);</span>
<span class="special">}</span>
</pre>
              </td></tr></tbody>
</table></div>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr><th>
                <p>
                  Output
                </p>
              </th></tr></thead>
<tbody><tr><td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="special">&gt;</span> <span class="identifier">decorator_06</span>
<span class="identifier">Running</span> <span class="number">1</span> <span class="identifier">test</span> <span class="keyword">case</span><span class="special">...</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">11</span><span class="special">):</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"test_io"</span><span class="special">:</span> <span class="identifier">check</span> <span class="number">1</span> <span class="special">!=</span> <span class="number">1</span> <span class="identifier">has</span> <span class="identifier">failed</span> <span class="special">[</span><span class="number">1</span> <span class="special">==</span> <span class="number">1</span><span class="special">]</span>

<span class="special">***</span> <span class="number">1</span> <span class="identifier">failure</span> <span class="identifier">is</span> <span class="identifier">detected</span> <span class="identifier">in</span> <span class="identifier">the</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"decorator_06"</span>


<span class="special">&gt;</span> <span class="identifier">decorator_06</span> <span class="special">--</span><span class="identifier">list_content</span>
<span class="identifier">test_io</span><span class="special">*</span>
<span class="identifier">test_db</span>
</pre>
              </td></tr></tbody>
</table></div>
<p>
        Decorator <code class="computeroutput"><span class="identifier">enable_if</span><span class="special">&lt;</span><span class="keyword">true</span><span class="special">&gt;()</span></code>
        is equivalent to decorator <code class="computeroutput"><span class="identifier">enabled</span><span class="special">()</span></code>. Similarly, <code class="computeroutput"><span class="identifier">enable_if</span><span class="special">&lt;</span><span class="keyword">false</span><span class="special">&gt;()</span></code> is equivalent to decorator <code class="computeroutput"><span class="identifier">disabled</span><span class="special">()</span></code>.
      </p>
<h4>
<a name="boost_test.tests_organization.enabling.h4"></a>
        <span class="phrase"><a name="boost_test.tests_organization.enabling.runtime_run_status"></a></span><a class="link" href="enabling.html#boost_test.tests_organization.enabling.runtime_run_status">Runtime
        run status</a>
      </h4>
<p>
        Decorator <a class="link" href="../utf_reference/test_org_reference/decorator_precondition.html" title="precondition (decorator)"><code class="computeroutput"><span class="identifier">precondition</span></code></a> associates a <span class="emphasis"><em>predicate</em></span>
        with a test unit. Before the test unit is executed, the predicate is evaluated
        with the test unit's ID passed as the argument. If it evaluates to <code class="computeroutput"><span class="keyword">false</span></code>, execution of the test unit is skipped.
        Skipping a test suite means skipping the execution of every test unit inside.
      </p>
<div class="tip"><table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../../../../doc/src/images/tip.png"></td>
<th align="left">Tip</th>
</tr>
<tr><td align="left" valign="top"><p>
          The precondition may return an <code class="computeroutput"><a class="link" href="../../boost/test_tools/assertion_result.html" title="Class assertion_result">assertion_result</a></code>
          instead of a boolean. In that case, the message contained in the <code class="computeroutput"><span class="identifier">assertion_result</span></code> will be printed by the
          <span class="emphasis"><em>Unit Test Framework</em></span>.
        </p></td></tr>
</table></div>
<h6>
<a name="boost_test.tests_organization.enabling.h5"></a>
        <span class="phrase"><a name="boost_test.tests_organization.enabling.example_descr1"></a></span><a class="link" href="enabling.html#boost_test.tests_organization.enabling.example_descr1">Example:
        decorator precondition</a>
      </h6>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr><th>
                <p>
                  Code
                </p>
              </th></tr></thead>
<tbody><tr><td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_MODULE</span> <span class="identifier">decorator_08</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">test</span><span class="special">/</span><span class="identifier">included</span><span class="special">/</span><span class="identifier">unit_test</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="keyword">namespace</span> <span class="identifier">utf</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">unit_test</span><span class="special">;</span>
<span class="keyword">namespace</span> <span class="identifier">tt</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">test_tools</span><span class="special">;</span>

<span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span><span class="identifier">test1</span><span class="special">)</span>
<span class="special">{</span>
  <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="keyword">true</span><span class="special">);</span>
<span class="special">}</span>

<span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span><span class="identifier">test2</span><span class="special">)</span>
<span class="special">{</span>
  <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="keyword">false</span><span class="special">);</span>
<span class="special">}</span>

<span class="keyword">struct</span> <span class="identifier">if_either</span>
<span class="special">{</span>
  <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">tc1</span><span class="special">,</span> <span class="identifier">tc2</span><span class="special">;</span>
  <span class="identifier">if_either</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">t1</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">t2</span><span class="special">)</span>
    <span class="special">:</span> <span class="identifier">tc1</span><span class="special">(</span><span class="identifier">t1</span><span class="special">),</span> <span class="identifier">tc2</span><span class="special">(</span><span class="identifier">t2</span><span class="special">)</span> <span class="special">{}</span>

  <span class="identifier">tt</span><span class="special">::</span><span class="identifier">assertion_result</span> <span class="keyword">operator</span><span class="special">()(</span><span class="identifier">utf</span><span class="special">::</span><span class="identifier">test_unit_id</span><span class="special">)</span>
  <span class="special">{</span>
    <span class="keyword">auto</span><span class="special">&amp;</span> <span class="identifier">master</span> <span class="special">=</span> <span class="identifier">utf</span><span class="special">::</span><span class="identifier">framework</span><span class="special">::</span><span class="identifier">master_test_suite</span><span class="special">();</span>
    <span class="keyword">auto</span><span class="special">&amp;</span> <span class="identifier">collector</span> <span class="special">=</span> <span class="identifier">utf</span><span class="special">::</span><span class="identifier">results_collector_t</span><span class="special">::</span><span class="identifier">instance</span><span class="special">();</span>
    <span class="keyword">auto</span><span class="special">&amp;</span> <span class="identifier">test1_result</span> <span class="special">=</span> <span class="identifier">collector</span><span class="special">.</span><span class="identifier">results</span><span class="special">(</span><span class="identifier">master</span><span class="special">.</span><span class="identifier">get</span><span class="special">(</span><span class="identifier">tc1</span><span class="special">));</span>
    <span class="keyword">auto</span><span class="special">&amp;</span> <span class="identifier">test2_result</span> <span class="special">=</span> <span class="identifier">collector</span><span class="special">.</span><span class="identifier">results</span><span class="special">(</span><span class="identifier">master</span><span class="special">.</span><span class="identifier">get</span><span class="special">(</span><span class="identifier">tc2</span><span class="special">));</span>

    <span class="keyword">if</span> <span class="special">(</span><span class="identifier">test1_result</span><span class="special">.</span><span class="identifier">passed</span><span class="special">()</span> <span class="special">||</span> <span class="identifier">test2_result</span><span class="special">.</span><span class="identifier">passed</span><span class="special">())</span>
      <span class="keyword">return</span> <span class="keyword">true</span><span class="special">;</span>

    <span class="identifier">tt</span><span class="special">::</span><span class="identifier">assertion_result</span> <span class="identifier">ans</span><span class="special">(</span><span class="keyword">false</span><span class="special">);</span>
    <span class="identifier">ans</span><span class="special">.</span><span class="identifier">message</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">tc1</span> <span class="special">&lt;&lt;</span> <span class="string">" and "</span> <span class="special">&lt;&lt;</span> <span class="identifier">tc2</span> <span class="special">&lt;&lt;</span> <span class="string">" failed"</span><span class="special">;</span>
    <span class="keyword">return</span> <span class="identifier">ans</span><span class="special">;</span>
  <span class="special">}</span>
<span class="special">};</span>

<span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span><span class="identifier">test3</span><span class="special">,</span>
  <span class="special">*</span> <span class="identifier">utf</span><span class="special">::</span><span class="identifier">precondition</span><span class="special">(</span><span class="identifier">if_either</span><span class="special">(</span><span class="string">"test1"</span><span class="special">,</span> <span class="string">"test2"</span><span class="special">)))</span>
<span class="special">{</span>
  <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="keyword">false</span><span class="special">);</span>
<span class="special">}</span>

<span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span><span class="identifier">test4</span><span class="special">,</span>
  <span class="special">*</span> <span class="identifier">utf</span><span class="special">::</span><span class="identifier">precondition</span><span class="special">(</span><span class="identifier">if_either</span><span class="special">(</span><span class="string">"test2"</span><span class="special">,</span> <span class="string">"test3"</span><span class="special">)))</span>
<span class="special">{</span>
  <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="keyword">false</span><span class="special">);</span>
<span class="special">}</span>
</pre>
              </td></tr></tbody>
</table></div>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr><th>
                <p>
                  Output
                </p>
              </th></tr></thead>
<tbody><tr><td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="special">&gt;</span> <span class="identifier">decorator_08</span> <span class="special">--</span><span class="identifier">log_level</span><span class="special">=</span><span class="identifier">test_suite</span>
<span class="identifier">Running</span> <span class="number">4</span> <span class="identifier">test</span> <span class="identifier">cases</span><span class="special">...</span>
<span class="identifier">Entering</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"decorator_08"</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">6</span><span class="special">):</span> <span class="identifier">Entering</span> <span class="identifier">test</span> <span class="keyword">case</span> <span class="string">"test1"</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">6</span><span class="special">):</span> <span class="identifier">Leaving</span> <span class="identifier">test</span> <span class="keyword">case</span> <span class="string">"test1"</span><span class="special">;</span> <span class="identifier">testing</span> <span class="identifier">time</span><span class="special">:</span> <span class="number">1</span><span class="identifier">ms</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">11</span><span class="special">):</span> <span class="identifier">Entering</span> <span class="identifier">test</span> <span class="keyword">case</span> <span class="string">"test2"</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">13</span><span class="special">):</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"test2"</span><span class="special">:</span> <span class="identifier">check</span> <span class="keyword">false</span> <span class="identifier">has</span> <span class="identifier">failed</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">11</span><span class="special">):</span> <span class="identifier">Leaving</span> <span class="identifier">test</span> <span class="keyword">case</span> <span class="string">"test2"</span><span class="special">;</span> <span class="identifier">testing</span> <span class="identifier">time</span><span class="special">:</span> <span class="number">2</span><span class="identifier">ms</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">39</span><span class="special">):</span> <span class="identifier">Entering</span> <span class="identifier">test</span> <span class="keyword">case</span> <span class="string">"test3"</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">41</span><span class="special">):</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"test3"</span><span class="special">:</span> <span class="identifier">check</span> <span class="keyword">false</span> <span class="identifier">has</span> <span class="identifier">failed</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">39</span><span class="special">):</span> <span class="identifier">Leaving</span> <span class="identifier">test</span> <span class="keyword">case</span> <span class="string">"test3"</span><span class="special">;</span> <span class="identifier">testing</span> <span class="identifier">time</span><span class="special">:</span> <span class="number">2</span><span class="identifier">ms</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">45</span><span class="special">):</span> <span class="identifier">Test</span> <span class="keyword">case</span> <span class="string">"test4"</span> <span class="identifier">is</span> <span class="identifier">skipped</span> <span class="identifier">because</span> <span class="identifier">test2</span> <span class="keyword">and</span> <span class="identifier">test3</span> <span class="identifier">failed</span>
<span class="identifier">Leaving</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"decorator_08"</span><span class="special">;</span> <span class="identifier">testing</span> <span class="identifier">time</span><span class="special">:</span> <span class="number">16</span><span class="identifier">ms</span>

<span class="special">***</span> <span class="number">2</span> <span class="identifier">failures</span> <span class="identifier">are</span> <span class="identifier">detected</span> <span class="identifier">in</span> <span class="identifier">the</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"decorator_08"</span>
</pre>
              </td></tr></tbody>
</table></div>
<p>
        In the example above, the user defined a custom predicate <code class="computeroutput"><span class="identifier">if_either</span></code>
        that evaluates to <code class="computeroutput"><span class="keyword">true</span></code> if at
        least one of the two specified tests passed. (It assumes that the tests are
        registered in the specific order.)
      </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
            Test case <code class="computeroutput"><span class="identifier">test3</span></code> has a
            precondition that at either <code class="computeroutput"><span class="identifier">test1</span></code>
            or <code class="computeroutput"><span class="identifier">test2</span></code> passed. The
            precondition is satisfied, therefore <code class="computeroutput"><span class="identifier">test3</span></code>
            is run (and fails),
          </li>
<li class="listitem">
            test case <code class="computeroutput"><span class="identifier">test4</span></code> has a
            precondition that either <code class="computeroutput"><span class="identifier">test2</span></code>
            or <code class="computeroutput"><span class="identifier">test3</span></code> passed. Since
            they both failed, the precondition is not satisfied, therefore <code class="computeroutput"><span class="identifier">test4</span></code> is skipped.
          </li>
</ul></div>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
          A <a class="link" href="../utf_reference/test_org_reference/decorator_precondition.html" title="precondition (decorator)"><code class="computeroutput"><span class="identifier">precondition</span></code></a> that evaluates to
          <code class="computeroutput"><span class="keyword">false</span></code> does not yield an error
          and does not fail the attached unit test. However the <span class="emphasis"><em>Unit Test
          Framework</em></span> returns an error if the test tree is empty (see <a class="link" href="test_tree/test_tree_content.html" title="Test tree content">this
          section</a> for more details).
        </p></td></tr>
</table></div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2001-2020 Boost.Test contributors<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="tests_grouping.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../tests_organization.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="semantic.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
